package com.c212.manager.handler;

import com.c212.manager.exception.AuthException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class ExceptionHandler {

    @org.springframework.web.bind.annotation.ExceptionHandler(value = AuthException.class)
//    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ModelAndView authExceptionHandler() {
        return new ModelAndView("redirect:/user/login");
    }

    @org.springframework.web.bind.annotation.ExceptionHandler(value = Exception.class)
    @ResponseStatus(HttpStatus.FORBIDDEN)
    public ModelAndView ExceptionHandler(Exception e) {
        Map<String, String> map = new HashMap<>();
        map.put("msg", "异常啦~" + e.getMessage());
        map.put("url", "/user/login");
        return new ModelAndView("/common/error", map);
    }
}